import {
	getDateString
} from "@/assets/js/common.js";
let Controller = {
	mounted() {
		this.requestTableList();
		this.getDowmList();
	},
	methods: {
		onTableCreate() {

		},
		onTableExport() {

		},
		getDowmList() {
			this.$ajax.post(this.apiTest + `/supplier/whWarehouse/getDropBox/206`,{})
				.then(response => {
					const data = response.data;
					if (data.status == 200) {
            const result = data.result;
            this.Model.filterOptionData = result;
            let locationArr = [], wareHouseStatusArr = [], wareHouseTypeArr = [];
            for (let i in result.location) {//入库仓库
              locationArr.push({ label: result.location[i], value: i });
            };
            for (let i in result.wareHouseStatus) {//入库单状态
              wareHouseStatusArr.push({ label: result.wareHouseStatus[i], value: i });
            };
            for (let i in result.wareHouseType) {//入库单类型
              wareHouseTypeArr.push({ label: result.wareHouseType[i], value: i });
            };
            this.Model.filterOption.items[2].data = locationArr;//入库仓库
            this.Model.filterOption.items[1].data = wareHouseStatusArr;//入库单状态
            this.Model.filterOption.items[4].data = wareHouseTypeArr;//入库单类型
            this.Model.defaultFilterOption = _.cloneDeep(this.Model.filterOption)
					}
				}).catch(err => {
					console.log(err)
				})
		},
		requestTableList() {
			//请求主表数据
			const params = {
				condition: {
					...this.getSearchInfoParam(),
					businessType: 50
				},
				...this.Model.pager.params,
			};

			this.$ajax
				.post(this.apiTest + `/supplier/whWarehouse/list`, params)
				// .post(this.apiTest + `/sale/onSale/order/list`, params)
				.then(response => {
					const data = response.data;
					if (data.status == 200) {
						this.Model.tableData = data.result.result;
						this.Model.pager.pageTotal = data.result.total;
						this.Model.pager.pageIndex = data.result.pageIndex;
					}
				})
				.catch(error => {
					this.$message.error('请求错误');
				});
		},
		getSearchInfoParam() {
			//编辑高级搜索时间格式
			let data = _.cloneDeep(this.Model.searchFromData);
			if (data.createTime) {
				data.createTimeStart = getDateString(data.createTime[0]);
				data.createTimeEnd = getDateString(data.createTime[1]);
				data.createTime = undefined;
			}
			if (data.sureTime) {
				data.sureTimeStart = getDateString(data.sureTime[0]);
				data.sureTimeEnd = getDateString(data.sureTime[1]);
				data.sureTime = undefined;
			}
			return data;
		},
		toTableDetail(row, flag) {
			//跳转入库详情
			const name = 'afterSaleWarehousingDetail';
			this.$router.push({
				name: name,
				query: {
					data: JSON.stringify({row,flag}),
				}
			})
		},
		onTableSelectionChange(val) {
			//表格多选操作
			if (val.length == 0) {
				this.Model.selectionList = [];
				return;
			}
			let arr = val.map((item, index, list) => {
				return item.id
			})
			this.Model.selectionList = arr;
		},
		onTableCurrentChange(val) {
			//表格分页-当前页变动操作
			this.Model.pager.params.pageIndex = val;
			this.requestTableList();
		},
		onTableSizeChange(val) {
			//表格分页-页数量变动操作
			this.Model.pager.params.pageSize = val;
			this.requestTableList();
		},
		onCardClick(color) {
			//页面card搜索点击操作
			this.Model.cardSelected = color;
		},
		getFilterData(val, item, option) {
			/* 
			 saleOrderStatus订单状态[1]
			 saleOrderTypes售中类型-状态联动[2][3]
			 saleOrderChannels销售渠道[4][5]
			 deliveryTypes发货方式[6]
			 */
			for (let i = 0; i < 5; i++) {
        this.Model.filterOption.items[i] = option[i];
      }
			this.Model.searchFromData = val;
		},
		onFilterSearch(val) {
			this.requestTableList();
		},
		onFilterClear(val) {
			this.Model.searchFromData = this.Model.defaultSearchFromData;
			this.Model.filterOption = this.Model.defaultFilterOption;
		},
		onFilterExport(val) {
			console.log(val);
		},
		onTabChange(val) {
			switch (val) {
				case 1:
					break;
				case 2:
					break;
				case 3:
					break;
			}
		},
		setPage(pageIndex, pageSize, pageTotal, total) {
			this.Model.pager.params = {
				pageIndex,
				pageSize
			};
			this.Model.pager.total = total;
		},
	}
}
export default Controller;
